<?php

namespace App\Requests\Admin\GoodsType;

use App\Enums\GoodsTypeStatusEnum;
use App\Models\BrandModel;
use App\Models\GoodsClass;
use App\Models\GoodsType;
use App\Requests\BaseRequest;
use App\Traits\ValidatorTrait;
use Illuminate\Validation\Rule;

class GoodsTypeSaveRequest extends BaseRequest
{
    use ValidatorTrait;

    /**
     * 字段注解
     *
     * @return array
     */
    public function attributes(): array
    {
        return [
            'id' => 'ID',
            'name' => '名称',
            'brand_id' => '品牌',
            'goods_class_id' => '品类',
            'status' => '状态',
        ];
    }

    public function rules(): array
    {
        return [
            'id' => ['sometimes', 'integer'],
            'name' => ['required', 'string'],
            'brand_id' => ['required', 'integer', Rule::exists(BrandModel::class, BrandModel::KEY),],
            'goods_class_id' => ['required', 'integer', Rule::exists(GoodsClass::class, GoodsClass::KEY)],
            'status' => ['required', Rule::in(GoodsTypeStatusEnum::getKeyList()),],
        ];
    }
}
